package business;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import util.JdbcUtils;

public class LoginBusiness {
	public String login(String username, String password){
		JdbcUtils jdbcUtils=new JdbcUtils();
		String str = null;
		Connection conn = null;
		PreparedStatement prep = null;
		ResultSet rs = null;
		try{
			conn = jdbcUtils.getConnection();
			prep = conn.prepareStatement("select state from user where name=? and password=?");
			prep.setString(1, username);
			prep.setString(2, password);
			rs = prep.executeQuery();
			if(rs.next())
				str = rs.getString("state");
//			System.out.println(str);
//			System.out.println("aaa"+username);
//			System.out.println("bbb"+password);
		}catch(SQLException e){
			e.printStackTrace();
			
		}finally{
			try{
				if(rs!=null){
					rs.close();
					rs = null;
				}
				if(prep!=null){
					prep.close();
					prep = null;
				}
				if(conn!=null){
					conn.close();
					conn = null;
				}
			}catch(SQLException e){
				e.printStackTrace();
				
			}
			
			
		}
		
            
		{ jdbcUtils.releaseConn();  }
	         
	            
	        
		
		return str;
		
	}

}
